package main

import (
	"fmt"
	"runtime"
	"time"
)

//select  实现 feibonacci 数列
func main() {
	ch := make(chan int, 0)
	quit := make(chan bool)
	go feibonacci(ch, quit)
	x, y := 1, 1
	for i := 0; i < 100; i++ {
		<-time.After(time.Second)
		ch <- x
		x, y = y, x+y

	}
	close(ch)
	quit <- true
	close(quit)

}

func feibonacci(ch <-chan int, quit chan bool) {

	for {

		select {
		case num := <-ch:
			fmt.Print(num, " ")
		case <-quit:
			runtime.Goexit()
		}
	}
}
